package com.ks.test.thread;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class test {
	public static void main(String[] args) throws Exception {
		// 创建一个线程池
        ExecutorService pool = Executors.newFixedThreadPool(2);
        // 创建两个有返回值的任务
        Student a = new Student();
        Student b = new Student();
        Callable c1 = new MyCallable("A",a);
        Callable c2 = new MyCallable("B",b);
 
        // 执行任务并获取Future对象
        Future<Student> f1 = pool.submit(c1);
        Future f2 = pool.submit(c2);
        
 
        // 从Future对象上获取任务的返回值，并输出到控制台
        System.out.println(">>>" + a.getName());
        System.out.println(">>>" + b.toString());
 
        // 关闭线程池
        pool.shutdown();
		
	}
	
}
